###############################################################################
##
##  Copyright (C) 2014 Tavendo GmbH
##
##  Licensed under the Apache License, Version 2.0 (the "License");
##  you may not use this file except in compliance with the License.
##  You may obtain a copy of the License at
##
##      http://www.apache.org/licenses/LICENSE-2.0
##
##  Unless required by applicable law or agreed to in writing, software
##  distributed under the License is distributed on an "AS IS" BASIS,
##  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
##  See the License for the specific language governing permissions and
##  limitations under the License.
##
###############################################################################

import os
import json
import pkg_resources

taschenmesser = pkg_resources.resource_filename('taschenmesser', '..')
#taschenmesser = "../../../infrequent/taschenmesser"
env = Environment(tools = ['default', 'taschenmesser'],
                  toolpath = [taschenmesser],
                  ENV = os.environ)

DOCSDIR = 'doc/html'
S3DIR = '_upload'

##
## Doxygen Build
##
docs = env.Command(DOCSDIR, [], "doxygen Doxyfile")
env.AlwaysBuild(docs)
Clean(docs, DOCSDIR)
Default(docs)


##
## Upload to Amazon S3
##
env['S3_RELPATH'] = DOCSDIR
env['S3_BUCKET'] = 'autobahn.ws'
env['S3_BUCKET_PREFIX'] = 'android/reference/' # note the trailing slash!
env['S3_OBJECT_ACL'] = 'public-read'


uploaded = []
import fnmatch

for root, dirnames, filenames in os.walk(DOCSDIR):
   for filename in filenames:
      source = os.path.join(root, filename)
      target = os.path.join(S3DIR, source)
      uploaded.append(env.S3('{}.s3'.format(target), source))

Depends(uploaded, docs)
Clean(docs, S3DIR)
Alias("publish", uploaded)

